package com.fili.params;

import java.util.ArrayList;

/**
 * Date: Nov 12, 2005
 * Time: 5:18:31 PM
 *
 * @author Claudiu-Florin FILIMON for Borux Consulting S.R.L.
 */
public class ListParam
{
	private Integer[] items;
/*-------------------------------------------------------------------------------------
    Getters and setters
 --------------------------------------------------------------------------------------*/

	public Integer[] getItems()
	{
		return items;
	}
/*-------------------------------------------------------------------------------------
	Constructors
 --------------------------------------------------------------------------------------*/

	public ListParam(Integer[] items)
	{
		this.items = items;
	}
/*-------------------------------------------------------------------------------------
    Methods
 --------------------------------------------------------------------------------------*/

	public static Integer[] parseList(String s)
	{
		ArrayList<Integer> obj = new ArrayList<Integer>();

		int p1, p2;
		p1 = 1;
		p2 = 1;

		while (s.charAt(p2) != ')')
		{
			while ((s.charAt(p2) != ',') && (s.charAt(p2) != ')'))
				p2++;
			obj.add(Integer.parseInt(s.substring(p1, p2)));
			if (s.charAt(p2) == ',')
				p2++;
			p1 = p2;
		}

		return obj.toArray(new Integer[0]);
	}
/*-------------------------------------------------------------------------------------
    Overrides
 --------------------------------------------------------------------------------------*/

	public String toString()
	{
		String s = "(";

		for (int i = 0; i < items.length; i++)
		{
			s += items[i];
			if (i < items.length - 1)
				s += ",";
		}
		s += ")";
		return s;
	}
/*-------------------------------------------------------------------------------------
    Implementations
 --------------------------------------------------------------------------------------*/
}
